package com.zqh.app.controller;

import com.alibaba.fastjson.JSON;
import com.zqh.app.entity.GroupInfo;
import com.zqh.app.entity.Push;
import com.zqh.app.manager.AppPushManager;
import com.zqh.app.manager.AppStatisticsManager;
import com.zqh.app.utils.jiguang.push.PushResult;
import com.zqh.common.entity.R;
import com.zqh.common.utils.DateUtils;
import com.zqh.common.utils.TimeUtils;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

@RestController
@RequestMapping("/push")
public class AppPushController {

    @Autowired
    private AppPushManager appPushManager;

    @Autowired
    private AppStatisticsManager appStatisticsManager;

    /**
     * 针对所有用户进行的推送
     *
     * @param
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：[{creatorId: 1,memberId:1,groupId:1,nicename: \"哈哈\"}]",dataType = "string",paramType = "body")
    @RequestMapping("/sendPush")
    public PushResult sendMessage(String params) {
        List<Push> map = JSON.parseArray(params, Push.class);
        return appPushManager.sendMessage(map);
    }


    /**
     * 推送测试
     *
     * @param
     * @return
     */
    @RequestMapping("/demo")
    public PushResult demo() throws ParseException {
         appPushManager.continuousFifteen();
         //appStatisticsManager.saveAllAppData();
         return null;
//        if (!appPushManager.isPush("push2",TimeUtils.getTime())){
//            System.out.println(123);
//            return null;
//        }
//        //Date a = DateUtils.getTomorrow();
//        boolean a = appPushManager.isPush("push1",TimeUtils.getTime());
//        System.out.println(a);
//        return null;
    }

}
